package com.shanling.shanlingcontroller.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.shanling.shanlingcontroller.R;
import com.shanling.shanlingcontroller.base.BaseAppCompatActivity;
import com.shanling.shanlingcontroller.base.BaseLazyFragment;
import com.shanling.shanlingcontroller.bean.EventCenter;
import com.shanling.shanlingcontroller.ui.fragment.LoacalMusicFragmentFactory;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LocalmusicaActivity extends BaseAppCompatActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tl)
    TabLayout tl;
    @BindView(R.id.vp)
    ViewPager vp;
    @BindView(R.id.iv_play)
    ImageView ivPlay;
    private List<String> titles = new ArrayList<>();
    private List<BaseLazyFragment> fragments = new ArrayList<>();

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_localmusica;
    }

    @Override
    protected void initViewsAndEvents() {
        titles.add(getString(R.string.localmusic_table1));
        titles.add(getString(R.string.localmusic_table2));
        titles.add(getString(R.string.localmusic_table3));
        titles.add(getString(R.string.localmusic_table4));
        titles.add(getString(R.string.localmusic_table5));
        titles.add(getString(R.string.localmusic_table6));
        fragments.add(LoacalMusicFragmentFactory.createFragment(0));
        fragments.add(LoacalMusicFragmentFactory.createFragment(1));
        fragments.add(LoacalMusicFragmentFactory.createFragment(2));
        fragments.add(LoacalMusicFragmentFactory.createFragment(3));
        fragments.add(LoacalMusicFragmentFactory.createFragment(4));
        fragments.add(LoacalMusicFragmentFactory.createFragment(5));
        vp.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {

                return fragments.size();

            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                super.destroyItem(container, position, object);
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return titles.get(position);
            }
        });
        tl.setupWithViewPager(vp);


    }

    @Override
    protected void initData() {

    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected void onEventComing(EventCenter eventCenter) {

    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        LoacalMusicFragmentFactory.onDestory();
    }



    @OnClick({R.id.iv_back, R.id.iv_play})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.iv_play:
                readyGo(MusicPlayActivity.class);
                break;
        }
    }
}
